package cn.tonyandmoney.voicenotes.utils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import cn.tonyandmoney.voicenotes.notes.filters.SearchFilter;

/**
 * 序列化
 */
public class GsonUtils {

    private static Gson mGson = new Gson();

    public static String toJson(Object obj) {
        return mGson.toJson(obj);
    }

    public static <T> T formJson(Class<T> cls, String json) {
        return mGson.fromJson(json, cls);
    }

    public static <T> List<T> fromJson(String src,Type type) {
        try {
            return mGson.fromJson(src, type);
        } catch (Exception e) {
            e.printStackTrace();
            return new ArrayList<>();
        }

    }

}
